<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ include file="../../base.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据 - AdminLTE2定制版</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 页面meta /-->
</head>
<script>
    function deleteById() {
        let id = getCheckId();
        if(id) {
            if(confirm("你确认要删除此条记录吗？")) {
                $.ajax({
                    url:"/cargo/invoice/delete",
                    data:{"id":id},
                    type:"post",
                    dataType:"json",
                    success:function (result) {
                        if (result.message == 1) {
                            alert("删除成功！")
                            location.reload();
                        } else {
                            alert("该发票已支付，不能删除！");
                        }
                    }
                })
            }
        }else{
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }
    function fance() {
        let id = getCheckId();
        if(id) {
                location.href="${ctx}/cargo/finance/add.do?id="+id;
        }else{
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }

    function setStatus() {
        let id = getCheckId();
        if(id) {
            location.href="${ctx}/cargo/invoice/setStatus.do?id="+id;
        }else{
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }

    function pdf() {
        let id = getCheckId();
        if(id) {
            location.href="${ctx}/cargo/invoice/printPdf.do?id="+id;
        }else{
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }

    function finance() {
        var id = getCheckId()
        if(id) {
            $.ajax({
                url:"/cargo/finance/checkState",
                data:{"id":id},
                type:"post",
                dataType:"json",
                success:function (result) {
                    if (result.message == 1) {
                        location.href="${ctx}/cargo/finance/add.do?id="+id;
                    } else {
                        alert("该发票未支付，不能生成财务报运单！");
                    }
                }
            })
        }else{
            alert("请勾选待处理的记录，且每次只能勾选一个")
        }
    }
</script>
<body>
<div id="frameContent" class="content-wrapper" style="margin-left:0px;">
    <!-- 内容头部 -->
    <section class="content-header">
        <h1>
            货运管理
            <small>发票管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="all-order-manage-list.html">货运管理</a></li>
            <li class="active">发票管理</li>
        </ol>
    </section>
    <!-- 内容头部 /-->
    <section class="content">
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">发票列表</h3>
            </div>

            <div class="box-body">
                <div class="table-box">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" title="删除" onclick='deleteById()'><i class="fa fa-trash-o"></i> 删除</button>
                                <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                <button type="button" class="btn btn-default" title="设置为已支付" onclick='setStatus()'><i class="fa fa-trash-o"></i>设置为已支付</button>
                                <button type="button" class="btn btn-default" title="生成PDF" onclick='pdf()'><i class="fa fa-trash-o"></i> 生成PDF</button>
                                <button type="button" class="btn btn-default" title="生成财务报运单" onclick='finance()'><i class="fa fa-trash-o"></i> 生成财务报运单</button>
                            </div>
                        </div>
                    </div>
                    <!--工具栏/-->
                    <!--数据列表-->
                    <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                        <thead>
                        <tr>
                            <th class="" style="padding-right:0px;">
                            </th>
                            <th class="sorting">序号</th>
                            <th class="sorting">报运合同号</th>
                            <th class="sorting">贸易条款</th>
                            <th class="sorting">发票金额</th>
                            <th class="sorting">发票时间</th>
                            <th class="sorting">发票状态</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${pageInfo.list}" var="invoice"  varStatus="st">
                            <tr>
                                <td><input type="checkbox" name="id" value="${invoice.id}"/></td>
                                <td>${st.count}</td>
                                <td>${invoice.scNo }</td>
                                <td>${invoice.tradeTerms}</td>
                                <td>${invoice.invoiceMoney}</td>
                                <td><fmt:formatDate value="${invoice.invoiceTime}" pattern="yyyy-MM-dd"/></td>
                                <td>${invoice.status==0?"未支付":"已支付"}</td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="box-footer">
                <jsp:include page="../../common/page.jsp">
                    <jsp:param value="${ctx}/cargo/invoice/list.do" name="pageUrl"/>
                </jsp:include>
            </div>
        </div>
    </section>

</div>
<!-- 内容区域 /-->
</body>

</html>